<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示功能授权tree</title>
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/icon.css">
	
	<script type="text/javascript" src="${ctx}/script/jquery.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/lhgdialog/lhgdialog.min.js?s=facebook"></script>
	
	<link rel="stylesheet" type="text/css" href="${ctx}/script/ztree/jquery.ztree.css">
	<script type="text/javascript" src="${ctx}/script/ztree/jquery.ztree.min.js"></script>
	
	<!-- 
	<link rel="stylesheet" type="text/css" href="${ctx}/script/treeview/jquery.treeview.css">
	<script type="text/javascript" src="${ctx}/script/jquery.cookie.js"></script>
	<script type="text/javascript" src="${ctx}/script/treeview/jquery.treeview.js"></script>
	<script type="text/javascript" src="${ctx}/script/treeview/jquery.treeview.edit.js"></script>
	<script type="text/javascript" src="${ctx}/script/treeview/jquery.treeview.async.js"></script>
	 -->
	 
	 
	<script type="text/javascript">
	<!--
		var dg = frameElement.lhgDG;
		dg.addBtn( 'ok', '确定', function(){ 
			//var zTreeObj =zTree1(setting, zNodes);
			//var nodes = zTree.getCheckedNodes(); //或  zTreeObj.getCheckedNodes(true);
			//alert(nodes[0].id + "," + nodes[0].name);
			submitForm();
		});
		
		var rowId = dg.curWin.$("#gridTable").getGridParam('selrow');
		var rowData = dg.curWin.$("#gridTable").getRowData(rowId);
		
		var zTree;
		var setting;

		setting = {
			open:true,
			isSimpleData : true,
    		treeNodeKey : "id",
    		treeNodeParentKey : "pId",
			checkable: true,
			checkType : { "Y": "s", "N": "s" },//CheckBox被勾选时，取消勾选时不影响父节点
			async: true,
			//asyncUrl: "showGnqxTree.action?czlbId=" + $("#czlbId").val(),  //获取节点数据的URL地址
			asyncUrl: "showGnqxTree.action?czlbId=" + rowData.ID,  //获取节点数据的URL地址
			asyncParam: ["id", "name"], //获取节点数据时，必须的数据名称，例如：id、name
			callback : {
		      click: zTreeOnClick,
		      asyncSuccess:zTreeOnAsyncSuccess
		    }
		};
		var zNodes =[];
		
		$(document).ready(function(){
			$("#czlbId").val(rowData.ID);
			zTree = $("#tree").zTree(setting, zNodes);
			//zTree.expandAll(true);
			//var nodes = zTree.getNodes();
		});
		
		function expandAll(expandSign) {
			zTree.expandAll(expandSign);
		}
		
		function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
		    alert(msg);
		}
		
		function zTreeOnClick(event, treeId, treeNode) {
			alert(treeNode.tId + ", " + treeNode.id + ", " + treeNode.name);
		}
		
		function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
	    	zTree.expandAll(true);
		}
		
		function submitForm() {
			var czlbId = $("#czlbId").val();
			var xtgns = "";
			var nodes = zTree.getCheckedNodes();
			for(var i = 0; i < nodes.length; i++) {
				if(xtgns == "")
					xtgns += nodes[i].id;
				else
					xtgns += "," + nodes[i].id;
			}
			var params = {
				"czlbId" : czlbId,
				"xtgns" : xtgns
			};
			var actionUrl = "addOrModGnqx.action";
			$.ajax( {
				url : actionUrl,
				data : params,
				dataType : "json",
				cache : false,
				error : function(textStatus, errorThrown) {alert("系统ajax交互错误: " + textStatus);},
				success : function(data, textStatus) {
					if (data.ajaxResult == "success") {
						new dg.curWin.$.dialog({id:'2',title:'信息提示页面',page:'${ctx}/success.jsp',rang:true,iconTitle:false}).ShowDialog();
						dg.cancel();
					} else {
						dg.curWin.alert("修改操作失败！");
					}
				}
			});
		}
	//-->		
	</script>
</head>
<body>
<form id="form">
<input type="hidden" id="czlbId" name="czlbId" value="${czlbId}"/>
<ul id="tree" class="tree"></ul>
</form>
</body>
</html>